from sys import argv                                #从sys导入argv模块
script,filename = argv                              #会对argv变量进行解包，第一个参数（文件名）放入script，第二个参数放入filename
print(f"We're going to erase {filename}.")          #输出“We're going to erase 文本文件名”
print("If you don't want that,hit CTRL-C.")         #输出“If you don't want that,hit CTRL-C.”
print("If you do want that,hit RETURN.")            #输出“If you do want that,hit RETURN.”
input("? ")                                         #输出？后提示用户输入
print("Opening the file...")                        #输出“Opening the file...”
target = open(filename,"w")                         #以写模式“w”打开filename文件后，把文件对象返回给target变量，注：以w模式打开文件，如果没有则会创建，如果存在则会清空
print("Truncating the file.Goodbye! ")              #输出“Truncating the file.Goodbye! ”
#target.truncate()                                  #清空文件 
print("Now I'm going to ask you for three lines.")  #输出“Now I'm going to ask you for three lines.”
line1 = input("line1: ")                            #输出line1后提示用户输入
line2 = input("line2: ")                            #输出line2后提示用户输入
line3 = input("line3: ")                            #输出line3后提示用户输入
print("I'm going to write these to the file.")      #输出“I'm going to write these to the file.”
# target.write(line1)                                 #往文件里写入line1
# target.write("\n")                                  #往文件里写入换行符
# target.write(line2)                                 #往文件里写入line2
# target.write("\n")                                  #往文件里写入换行符
# target.write(line3)                                 #往文件里写入line3
# target.write("\n")                                  #往文件里写入换行符
target.write(line1 + "\n" + line2 + '\n' + line3 + '\n')
print("And finally,we close it.")                   #输出“And finally,we close it.”
target.close()                                      #关闭文件